package com.yige.service.mongoService

import com.mongodb.BasicDBObject
import com.mongodb.DBCollection
import com.mongodb.DBCursor
import com.mongodb.DBObject
import com.yige.common.SystemConstant
import com.yige.service.IncomeService
import org.springframework.stereotype.Service

/**
 * Created by sunhao on 2015/10/15 0015.
 */

@Service
class MongoIncomeService extends BasicMongoServiceImp implements IncomeService{
    @Override
    DBCollection getCollection() {
        return mongoTemplate.getCollection(SystemConstant.MONGODB_COL_INCOME)
    }

    @Override
    boolean changeStatus(Object incomeId, int status) {
        getCollection().update([_id:incomeId]as BasicDBObject,[$set:[status:status]as BasicDBObject]as BasicDBObject,true,true)
        return true
    }

    @Override
    List<DBObject> findNoPayStudent() {
        List<DBObject> list = new ArrayList<>()
        DBObject dbObject
        DBCursor cursor = getCollection().find([status: 0]as BasicDBObject)
        while (cursor.hasNext()){
            dbObject = cursor.next()
            list.add(dbObject)
        }
        return list
    }
}
